package com.itheima.demo;

import com.itheima.domain.UserDemo;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class DemoTest {

    private SqlSession session=null;
    private InputStream is=null;
    @Before
   public void before() throws IOException {
       is = Resources.getResourceAsStream("configMybatis.xml");
       SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
       session = factory.openSession();
   }
   @After
   public void after() throws IOException {
       session.commit();
       is.close();
   }

   @Test
   public void test1(){
       List<UserDemo> list = session.selectList("one.findAll");
       System.out.println(list);
   }

   @Test
    public void test2(){
       UserDemo user = session.selectOne("one.findByID", 2);
       System.out.println(user);
   }
}
